#include "Device.hpp"

namespace red {
	Device* Device::mMainDevice = 0;

	const char LuaDevice::className[] = "Device";
	Lunar<LuaDevice>::RegType LuaDevice::methods[] = {
		LunarMethod(LuaDevice, GetGui),
		LunarMethod(LuaDevice, GetInputs),
		LunarMethod(LuaDevice, GetWindow),
		{ 0 }
	};

	Device::Device() : mState(false), mBackgroundColor(Color::Grey){
		mMainDevice = this;
	}

	void Device::Initialize(u32 pWindowWidth, u32 pWindowHeight, const std::string &pWindowTitle){
		// Initialize Lua Classes
		InitializeLuaClass();

		// Initialize Window, Inputs and Gui
		mWindow.Initialize(pWindowWidth, pWindowHeight, pWindowTitle);
		mInput.Initialize(mWindow);
		mGui.Initialize(mWindow);

		mState = true;
	}

	void Device::InitializeLuaClass(){
		Lunar<LuaDevice>::Register(mLua);
		Lunar<ui::LuaGui>::Register(mLua);
	}

	void Device::Shutdown(){
		mWindow.Close();
		mState = false;
	}

	void Device::BeginRender(){
		mWindow.ClearBackground(mBackgroundColor);
	}

	void Device::EndRender(){
		mWindow.Display();
	}



}
